<template>
    <div>
        <div class="item" v-for="(v,i) in list">
<div class="title">{{i+1}}·{{ v.title }}（{{ v.type==1?'单选题':v.type==2?'多选题':'判断题' }}）  {{ v.jifen }}分   {{ v.status==1?'正确':v.status==2?'错误':'' }} 
<span v-if="v.status==2">正确答案{{ v.daan }}</span>

</div>
            <div class="list">
                <el-checkbox-group v-model="v.udaan" :max="v.type!=2?1:6" :disabled="disabled">
    <div>
        <el-checkbox :label="vv.zimu" v-for="vv in v.list" >{{vv.zimu}}.{{ vv.title }}</el-checkbox>
    </div>
  </el-checkbox-group>

            </div>
        </div>
        <el-button type="primary" :disabled="disabled"  @click="tijiao">提交考试</el-button>
    </div>
</template>

<script>
import api from "@/api/index"
    export default {
        data() {
            return {
                dizhi: {},
                list:[],
                gouwu:false,
                disabled:false
            }
        },
          computed: {
          
        },
        methods: {
            tijiao(){
                let index= this.list.findIndex(v=>!v.udaan || !v.udaan.length)
if(index!=-1){
    return   this.$message({
                        message: `第${index+1}题不能为空`,
                        type: 'warning'
                    });
}
                this.list.forEach(v=>{
                    v.udaan=v.udaan.join(',')
                    v.uid=this.$store.state.user.id
                })
                api.udaanadd(this.list).then(res=>{
this.getList()
                })
                console.log(this.list);
            },
            getList(){
                api.timulist({
            vid:this.$route.query.vid,
            uid:this.$store.state.user.id
         }).then(res=>{
            this.list=res.data
            this.list.forEach(v=>{
                v.udaan=v.udaan?v.udaan.split(","):[]
                v.list.forEach((vv,i)=>{
                    
                    vv.zimu=i==0?'A':i==1?'B':i==2?'C':'D'
                    return vv
                })
                this.disabled=this.list[0].udaan.length
                api.getUSer({uid:this.$store.state.user.id}).then(res=>{
                this.$store.commit("SET_USER", res.data)
                localStorage.setItem('user', JSON.stringify(res.data))
            })
            })
            console.log(this.list);
         })
            }
        },
        mounted () {
         this.getList()
        },
    }
</script>

<style lang="scss" scoped>
.item{
    border-bottom: 1px solid #ddd;
    padding: 20px;
    font-size: 18px;
    .list{
        padding: 10px 20px;
    }
}

</style>